package homework4

import akka.actor.{Actor, ActorRef, ActorSystem, Props}

class AActor extends Actor {

  val aActorRef = ActorSystem("myFactory").actorOf(Props[AActor], "bActor")

  override def receive: Receive = {
    case ("挺猛，看我降龙十八掌...第1掌", actorRef: ActorRef) => {
      val str = "厉害！佛山无影脚 第1脚"
      sendMessage(str, actorRef)
    }
    case ("挺猛，看我降龙十八掌...第2掌", actorRef: ActorRef) => {
      val str = "厉害！佛山无影脚 第2脚"
      sendMessage(str, actorRef)
    }
    case "到此为止吧！" => {
      //关闭自己
      context.stop(self)
      //关闭ActorSystem
      context.system.terminate()
    }

  }

  def sendMessage(str: String, actorRef: ActorRef): Unit = {
    println(s"AActor(黄飞鸿): $str")
    actorRef ! (str, aActorRef)
  }
}
